home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Environments
/
Small Eiffel 0.4.8
/
lib_std
/
std_file_write.e
< prev
next >
Wrap
Text File
|
1997-04-13
|
4KB
|
212 lines
-- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C)
-- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
--
class STD_FILE_WRITE
--
-- Basic output facilities to write a named file on the disk.
--
-- Note : most features are common with STD_OUTPUT so you can
-- test your program first on the screen and then, changing
-- of instance (STD_OUTPUT/STD_FILE_WRITE), doing the same
-- on a file.
--
inherit STD_FILE
creation
connect_to, make
feature
connect_to(new_path: STRING) is
do
make;
output_stream := fopen(new_path,mode);
if output_stream.is_not_void then
path := new_path;
end;
end;
disconnect is
local
err: INTEGER;
do
err := fclose(output_stream);
path := Void;
end;
make is
do
mode := "w";
end;
feature
put_character(c: CHARACTER) is
local
err: CHARACTER;
do
err := fputc(c,output_stream);
debug
if err /= c then
std_error.put_string("Error in STD_FILE_WRITE.put_character.%N");
crash;
end;
end;
end;
put_string(s: STRING) is
-- Output `s' to current output device.
require
s /= Void;
local
i: INTEGER;
do
from
i := 1;
until
i > s.count
loop
put_character(s.item(i));
i := i + 1;
end;
end;
put_integer (i: INTEGER) is
-- Output `i' to current output device.
do
tmp_string.clear;
i.append_in(tmp_string);
put_string(tmp_string);
end;
put_integer_format(i, s: INTEGER) is
-- Output `i' to current output device using at most
-- `s' character.
do
tmp_string.clear;
i.append_in_format(tmp_string,s);
put_string(tmp_string);
end;
put_real(r: REAL) is
-- Output `r' to current output device.
do
tmp_string.clear;
r.append_in(tmp_string);
put_string(tmp_string);
end;
put_real_format(r: REAL; f: INTEGER) is
-- Output `r' with only `f' digit for the fractionnal part.
-- Examples:
-- put_real(3.519,2) print "3.51".
require
f >= 0;
do
tmp_string.clear;
r.append_in_format(tmp_string,f);
put_string(tmp_string);
end;
put_double(d: DOUBLE) is
-- Output `d' to current output device.
do
tmp_string.clear;
d.append_in(tmp_string);
put_string(tmp_string);
end;
put_double_format(d: DOUBLE; f: INTEGER) is
-- Output `d' with only `f' digit for the fractionnal part.
-- Examples:
-- put_double(3.519,2) print "3.51".
require
f >= 0;
do
tmp_string.clear;
d.append_in_format(tmp_string,f);
put_string(tmp_string);
end;
put_boolean(b: BOOLEAN) is
-- Output `b' to current output device according
-- to the Eiffel format.
do
if b then
put_string("true");
else
put_string("false");
end;
end;
put_new_line is
-- Output a newline character.
do
put_character('%N');
end;
put_spaces(nb: INTEGER) is
-- Output `nb' spaces character.
require
nb >= 0;
local
count : INTEGER;
do
from
until
count >= nb
loop
put_character(' ');
count := count + 1;
end;
end;
append_file(file_name: STRING) is
require
file_exists(file_name);
local
c: CHARACTER;
do
tmp_file_read.connect_to(file_name);
from
tmp_file_read.read_character;
until
tmp_file_read.end_of_input
loop
c := tmp_file_read.last_character;
put_character(c);
tmp_file_read.read_character;
end;
tmp_file_read.disconnect;
end;
flush is
local
err: INTEGER;
do
err := fflush(output_stream);
end;
feature {NONE}
tmp_file_read: STD_FILE_READ is
once
!!Result.make;
end;
feature {NONE}
--
-- NOTE: use only a few basic ANSI C functions.
-- Try to use as few external C calls as possible.
--
output_stream: POINTER;
tmp_string: STRING is
once
!!Result.make(512);
end;
end -- STD_FILE_WRITE